$(function () {
    $("#jqGrid").Grid({
        url: '../regularmaintenancerecords/list',
        colModel: [
            {label: '维护计划名称', name: 'maintePlanName', index: 'MAINTE_PLAN_NAME', width: 80},
            {label: '维护部门', name: 'mainteDept', index: 'MAINTE_DEPT', width: 80},
            {label: '维护人员', name: 'mainteStaff', index: 'MAINTE_STAFF', width: 80},
            {label: '维护时间', name: 'mainteTime', index: 'MAINTE_TIME', width: 80,
                formatter: function (value) {
                    return transDate(value, "yyyy-MM-dd");
                }
             },
            // {label: '创建人', name: 'creater', index: 'CREATER', width: 80},
            // {label: '创建时间', name: 'createTime', index: 'CREATE_TIME', width: 80},
            // {label: '效果确认时间', name: 'effectConfirmTime', index: 'EFFECT_CONFIRM_TIME', width: 80},
            // {label: '效果确认情况', name: 'effectConfirmInfo', index: 'EFFECT_CONFIRM_INFO', width: 80},
            // {label: '备注', name: 'remake', index: 'REMAKE', width: 80},
            {label: '产品类型', name: 'productType', index: 'PRODUCT_TYPE', width: 80},
            {label: '产品系列', name: 'productSeries', index: 'PRODUCT_SERIES', width: 80},
            {label: '操作时间', name: 'operateTime', index: 'OPERATE_TIME', width: 80,
                formatter: function (value) {
                    return transDate(value, "yyyy-MM-dd");
                }},
            // {label: '维护人接受时间', name: 'mainteAcceptTime', index: 'MAINTE_ACCEPT_TIME', width: 80},
            // {label: '计划维护日期', name: 'planMainteTime', index: 'PLAN_MAINTE_TIME', width: 80},
            // {label: '上次维护日期', name: 'lastMainteTime', index: 'LAST_MAINTE_TIME', width: 80},
            {label: '是否上传记录', name: 'isUpload', index: 'IS_UPLOAD', width: 80,
                formatter: function (value) {
                    return sysEnums.IS_UPLOD[value];
                }},
            // {label: '原因', name: 'reason', index: 'REASON', width: 80},
            {label: '是否停止', name: 'isStop', index: 'IS_STOP', width: 80,
                formatter: function (value) {
                    return sysEnums.IS_STOP[value];
                }},
            // {label: '效果确认人', name: 'effectConfirmer', index: 'EFFECT_CONFIRMER', width: 80},
            {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            {label: '维护计划id', name: 'maintePlanId', index: 'MAINTE_PLAN_ID', hidden: true},
        ]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        regularMaintenanceRecords: {
            delFlag: '',
            creater: '',
            createTime: '',
            effectConfirmer: '',
            effectConfirmTime: '',
            effectConfirmInfo: '',
            remake: '',
            productType: '',
            productSeries: '',
            operateTime: '',
            mainteAcceptTime: '',
            planMainteTime: '',
            lastMainteTime: '',
            isUpload: '',
            reason: '',
            isStop: '',
            mainteDept: '',
            mainteStaff: '',
            mainteTime: '',
            maintePlanId: '',
            id: '',
        },
        ruleValidate: {
            name: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ]
        },
        q: {
            name: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.regularMaintenanceRecords = {
                delFlag: '',
                creater: '',
                createTime: '',
                effectConfirmer: '',
                effectConfirmTime: '',
                effectConfirmInfo: '',
                remake: '',
                productType: '',
                productSeries: '',
                operateTime: '',
                mainteAcceptTime: '',
                planMainteTime: '',
                lastMainteTime: '',
                isUpload: '',
                reason: '',
                isStop: '',
                mainteDept: '',
                mainteStaff: '',
                mainteTime: '',
                maintePlanId: '',
                id: '',
            };
        },
        update: function (event) {
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id);
        },
        saveOrUpdate: function (event) {
            var url = vm.regularMaintenanceRecords.id == (null || '') ? "../regularmaintenancerecords/save" : "../regularmaintenancerecords/update";
            Ajax.request({
                url: url,
                params: JSON.stringify(vm.regularMaintenanceRecords),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        del: function (event) {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    url: "../regularmaintenancerecords/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../regularmaintenancerecords/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.regularMaintenanceRecords = r.regularMaintenanceRecords;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        reloadSearch: function () {
            vm.q = {
                name: ''
            };
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        }
    }
});